package ym.ai.config;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ym.ai.service.IChatAssistant;

/**
 * 大模型配置
 */
@Configuration
public class LLMConfig {

    @Bean
    public ChatLanguageModel chatLanguageModel() {
        return OpenAiChatModel.builder()
                .apiKey("sk-aa74ecbcd54745ca88028dfa5f070033")
                .modelName("qwen-plus")
                .logRequests(true)//请求日志
                .logResponses(true)//响应日志
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }

    @Bean
    public StreamingChatLanguageModel streamingChatLanguageModel() {
        return OpenAiStreamingChatModel.builder()
                .apiKey("sk-aa74ecbcd54745ca88028dfa5f070033")
                .modelName("qwen-max-2025-01-25")
                .logRequests(true)//请求日志
                .logResponses(true)//响应日志
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }


    @Bean
    public IChatAssistant chatAssistant() {
        return AiServices.
                builder(IChatAssistant.class)
                //聊天
                .chatLanguageModel(chatLanguageModel())
                // 聊天【流式输出】
                .streamingChatLanguageModel(streamingChatLanguageModel())
                .build();
    }


}
